import {
  defineStore
} from "pinia";
import {
  computed,
  ref
} from "vue";

export const useAllDataStore = defineStore('allData', () => {
  const tagList = ref([{
      name: "vue"
    },
    {
      name: "markdown"
    }, {
      name: "git"
    },
    {
      name: "webpack"
    },
    {
      name: "vite"
    },{
      name: "面试"
    },{
      name: "React"
    }
  ])
  //文章列表
  const articleList = ref([{
      id: "2025081401",
      title: "关于markdown基础语法",
      category: "技术文章",
      tags: "markdown",
      time: "2025",
      content: "本篇只简单介绍一下markdown的基本语法",
    }, {
      id: "2025081402",
      title: "git基础语法",
      category: "技术文章",
      tags: "git",
      time: "2025",
      content: "git的基本使用语法",
    }, {
      id: "2025081601",
      title: "webpack的基本使用",
      category: "技术文章",
      tags: "webpack",
      time: "2025",
      content: "如题",
    }, {
      id: "2025081801",
      title: "vite的基本使用",
      category: "技术文章",
      tags: "vite",
      time: "2025",
      content: "如题",
    },{
      id: "2025081901",
      title: "文件上传及文件相关操作",
      category: "面试",
      tags: "面试",
      time: "2025",
      content: "如题",
    },{
      id: "2025082101",
      title: "React核心语法",
      category: "技术文章",
      tags: "React",
      time: "2025",
      content: "如题",
    },{
      id: "2025082401",
      title: "react中的常用hook",
      category: "技术文章",
      tags: "React",
      time: "2025",
      content: "如题",
    },{
      id: "2025082402",
      title: "hook的闭包陷阱的成因和解决方案",
      category: "技术文章",
      tags: "React",
      time: "2025",
      content: "如题",
    }
  ])
  //分类数组
  const categoryList = ref([{
    name: "技术文章",
    num: computed(() => {
      return articleList.value.filter(article => article.category === "技术文章").length
    })
  }, {
    name: "生活随笔",
    num: computed(() => {
      return articleList.value.filter(article => article.category === "生活随笔").length
    })
  }, {
    name: "面试",
    num: computed(() => {
      return articleList.value.filter(article => article.category === "面试").length
    })
  }, {
    name: "前端开发",
    num: computed(() => {
      return articleList.value.filter(article => article.category === "前端开发").length
    })
  }, {
    name: "项目经验",
    num: computed(() => {
      return articleList.value.filter(article => article.category === "项目经验").length
    })
  }, ])
  //计算2025年文章总数
  const count2025 = computed(() => {
    return articleList.value.filter(article => article.time === "2025").length
  })
  //2025年文章数组
  const articleList2025 = computed(() => {
    return articleList.value.filter(article => article.time === "2025")
  })
  //分类查找
  const categorySearch = (category) => {
    return articleList.value.filter(article => article.category === category)
  }
  //标签查找
  const tagSearch = (tag) => {
    return articleList.value.filter(article => article.tags === tag)
  }
  //归档数组
  const timeList = ref([{
    name: 2025,
    num: count2025
  }])
  return {
    tagList,
    categoryList,
    timeList,
    articleList,
    count2025,
    articleList2025,
    categorySearch,
    tagSearch
  }
})
